package cn.edu.gzgs.mapper;

import cn.edu.gzgs.entity.UserKnownIp;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserKnownIpMapper extends BaseMapper<UserKnownIp> {

    @Select("SELECT * FROM user_known_ips WHERE user_id = #{userId} AND ip_address = #{ipAddress}")
    UserKnownIp findByUserIdAndIpAddress(@Param("userId") Long userId, @Param("ipAddress") String ipAddress);

    @Select("SELECT COUNT(DISTINCT ip_address) FROM user_known_ips WHERE user_id = #{userId}")
    int countDistinctIpsByUserId(@Param("userId") Long userId);

    // 可选：获取用户所有已知IP，用于更复杂的相似度比较
    @Select("SELECT ip_address FROM user_known_ips WHERE user_id = #{userId}")
    List<String> findIpAddressesByUserId(@Param("userId") Long userId);
} 